home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #2
/
Monster Media No. 2 (Monster Media)(1994).ISO
/
prog_bas
/
txtprn.zip
/
TXTPRN.BAS
< prev
Wrap
BASIC Source File
|
1994-06-14
|
4KB
|
98 lines
Sub textprint ()
'Check for text in text box; exit if none.
If Text1.Text = "" Then
msg$ = "Nothing to print."
MsgBox msg$
Exit Sub
End If
'Get font size from user (12 pt. default)...exit if Cancel
prompt$ = "Enter an font size (Arial) in points. Left margin is 1.5 inches, others are 1 inch. For other formatting, load .LEC file into any word processor."
setfontsize$ = InputBox(prompt$, "Prompter", "12")
If setfontsize$ = "" Then Exit Sub
setsize = Val(setfontsize$)
screen.MousePointer = 11 'Set hourglass pointer
temp$ = Text1.Text 'Stores text box text in temporary variable
On Error Resume Next ' Reverts to defaults if font or size invalid
printer.ScaleMode = 5 ' Sets printer scale mode to inches
printer.FontName = "Arial" 'Sets printer font
printer.FontSize = setsize 'Sets printer font size to user value.
printer.CurrentY = .5 'Sets top margin for header
printer.CurrentX = 1.25 'Sets left margin with allowance for printer non-printing area
pageno = 1 'starts page number count for header
'Prints header line on first page
'thefile$ is a global variable from the program this came from.
printer.Print UCase$(thefile$); " "; Date$; " -- Page "; pageno
printer.CurrentY = 1 ' Sets top margin for actual text
'Loop below parses temp$
For x = 1 To Len(temp$)
'Loop adds characters to print string until width too wide for margins
Do
thisline$ = thisline$ + Mid$(temp$, x, 1) 'gets single character from string
If Right$(thisline$, 1) = Chr$(10) Then ' Checks for linefeed character and sends string to printer
thisline$ = Left$(thisline$, Len(thisline$) - 2) 'removes newline character from print string
If printer.CurrentY + printer.TextHeight(thisline$) > 10 Then GoTo nextpage 'checks for bottom margin
GoTo doprint 'branches to print routine
End If
x = x + 1 'resets loop parameter
Loop Until printer.TextWidth(thisline$) > 6 'maximum line width (calculated)
'tests for space at end of line...if not there, moves backward to find last space
If Right$(thisline$, 1) = " " Then x = x - 1 'resets loop parameter back one to compensate
If Right$(thisline$, 1) <> " " Then
'Looks for last space in printer string
For checkchar = Len(thisline$) To 1 Step -1
testchar$ = Mid$(thisline$, checkchar, 1)
x = x - 1 'resets loop parameter back one to compensate
'Found space? Exit loop
If testchar$ = " " Then
Exit For
End If
thisline$ = Left$(thisline$, Len(thisline$) - 1)
Next checkchar
End If
'Check again for bottom margin for safety's sake before falling through to print routine
If printer.CurrentY + printer.TextHeight(thisline$) > 10 Then GoTo nextpage
doprint:
thisline$ = Left$(thisline$, Len(thisline$)) ' trim printer string
printer.CurrentX = 1.25 'set left margin (must do for each line printed)
printer.Print thisline$ 'print the line
thisline$ = "" 'set thisline$ variable to empty
Next x
printer.EndDoc 'end print job
screen.MousePointer = 0 'restore mousepointer
Exit Sub ' avoids falling through to nextpage label
'Routine to jump to next page--sorry for the GoTos
nextpage:
printer.NewPage
'Reset all printer settings -- required for some printer drivers
printer.ScaleMode = 5
printer.FontName = "Arial"
printer.FontSize = setsize
printer.CurrentY = .5
printer.CurrentX = 1.25
pageno = pageno + 1
printer.Print UCase$(thefile$); " -- Page "; pageno ' print header for new pages
'reset margins for next actual text line
printer.CurrentX = 1.25
printer.CurrentY = 1
GoTo doprint 'return to print routine
End Sub